package com.groupbuying.store.controller.forInternal;

import com.groupbuying.store.service.StoreCapitalVirtualAccountService;
import com.groupbuying.store.utils.JSONUtils;
import com.groupbuying.store.utils.R;
import com.groupbuying.store.utils.ReturnUtils;
import com.groupbuying.store.utils.apiresult.ApiResult;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @anthor wenguoqiang
 * @date: 2019/04/03 17:04
 * @company 够样
 * @des
 **/
@RestController
@RequestMapping("/storeVirtualAccount")
public class StoreVirtualAccountController {

    private static Logger log = LoggerFactory.getLogger(StoreVirtualAccountController.class);

    @Autowired
    private StoreCapitalVirtualAccountService storeCapitalVirtualAccountService;


    @ApiOperation(value = "查询虚拟账户详情", notes = "查询虚拟账户详情")
    @PostMapping("/queryStoreVirtualAccountInfo")
    @ResponseBody
    public Object queryStoreVirtualAccountInfo(Map<String,Object> param){
        return ReturnUtils.appendResultStr(log,JSONUtils.beanToJson(storeCapitalVirtualAccountService.queryStoreVirtualAccountInfo(param)), "/storeVirtualAccount/queryStoreVirtualAccountInfo");
    }



    @ApiOperation(value = "冻结或者解冻虚拟金额", notes = "冻结或者解冻虚拟金额")
    @GetMapping("/freezeOrUnFreezeVirtualMoney")
    public ApiResult freezeVirtualMoney(@RequestParam Map<String, Object> params){
        return storeCapitalVirtualAccountService.freezeOrUnFreezeVirtualMoney(params);
    }

    @ApiOperation(value = "提现", notes = "提现")
    @GetMapping("/withdraw")
    public ApiResult withdraw(){
        return storeCapitalVirtualAccountService.withdraw();
    }

    @ApiOperation(value = "提现", notes = "提现")
    @GetMapping("/manualwithdraw")
    public ApiResult manualwithdraw(@RequestParam Map<String, Object> params){
        return storeCapitalVirtualAccountService.manualwithdraw(params);
    }

    @ApiOperation(value = "处理冻结金额", notes = "处理冻结金额")
    @GetMapping("/dealFreezeVirtulaMoney")
    public ApiResult dealFreezeVirtulaMoney(@RequestParam Map<String, Object> params){

        return storeCapitalVirtualAccountService.dealFreezeVirtulaMoney(params);

    }
    @ApiOperation(value = "处理虚拟账户金额", notes = "处理虚拟账户金额")
    @GetMapping("/dealStoreVirtualAccount")
    @ResponseBody
    public ApiResult dealStoreVirtualAccount(Map<String,Object> param){
        return storeCapitalVirtualAccountService.dealStoreVirtualAccount(param);
    }

    /*虚拟账号支付密码查询*/
    @GetMapping("/virtualAccountPassword")
    @ResponseBody
    public ApiResult virtualAccountPassword(@RequestParam("counterId") String counterId){
        log.error("virtualAccountPassword params:::"+counterId);
        String pwd=  storeCapitalVirtualAccountService.getAccontPwdByCounterId(counterId);
        log.error("virtualAccountPassword result:::"+pwd);
        if(StringUtils.isEmpty(pwd)){
            return ApiResult.failure();
        }else{
            return ApiResult.success(pwd);
        }
    }

}
